﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using SSP;

namespace SSP
{
    class SSPCharacter : SSPNode
    {
        public float vertVel;
        public double vertAccel;

        public SSPSprite idle;
        public SSPSprite walk;
        public SSPSprite attack;
        public SSPSprite dead;

        public int health;
        public int damage;
        public float range;

        public bool isAttacking;
        public bool isJumping;
        public bool isAlive;

        public string type;

        public int buffer;

        public SSPCharacter()
        {
            vertVel = 0;
            vertAccel = 0;

            idle = new SSPSprite();
            walk = new SSPSprite();
            attack = new SSPSprite();
            dead = new SSPSprite();
        }

        public override void update()
        {
            if (health <= 0 && isAlive)
            {
                isAlive = false;
                //Console.WriteLine("dead");
                this.Dead();
            }
            else
            {
                vertVel = vertVel + 5f;

                if (position.Y >= 700 && vertVel >= 0)
                {
                    vertVel = 0;
                    position.Y = 700;
                }
                position = new Vector2(position.X, (float)(position.Y + vertVel));

                idle.absolutePosition = position;
                walk.absolutePosition = position;
                attack.absolutePosition = position;
                dead.absolutePosition = position;
            }
            

            if (idle.visible)
            {
                idle.update();
            }
            else if (walk.visible)
            {
                walk.update();
            }
            else if (attack.visible)
            {
                attack.update();
            }
            else if (dead.visible)
            {
                dead.update();
            }
            else
            {
            }

        }

        public override void draw()
        {
            if (idle.visible)
            {
                idle.draw();
            }
            else if (walk.visible)
            {
                walk.draw();
            }
            else if (attack.visible)
            {
                attack.draw();
            }
            else if (dead.visible)
            {
                dead.draw();
            }
            else
            {
            }
        }

        public virtual void MoveRight()
        {
            attack.visible = false;
            idle.visible = false;
            walk.visible = true;
            walk.flipX = false;
            dead.visible = false;
        }

        public virtual void MoveLeft()
        {
            attack.visible = false;
            idle.visible = false;
            walk.visible = true;
            walk.flipX = true;
            dead.visible = false;
        }

        public void Idle()
        {
            attack.visible = false;
            idle.visible = true;
            walk.visible = false;
            dead.visible = false;
        }

        public void Dead()
        {
            attack.visible = false;
            idle.visible = false;
            walk.visible = false;
            dead.visible = true;
        }

        public void Attack()
        {
            //SSPAudio.GetInstance.AttackSFX();
            attack.visible = true;
            idle.visible = false;
            walk.visible = false;
            dead.visible = false;
        }

        public void Hide()
        {
            attack.visible = false;
            idle.visible = false;
            walk.visible = false;
            dead.visible = false;
        }

        public void Jump()
        {
            if (position.Y > 10 )
            {
                vertVel = -70;
            }
            else
            {
            }
            
        }
    }
}
